package jinyilw.swing.rlaf.theme;

import jinyilw.swing.rlaf.UITools;

import java.awt.Color;
import java.awt.PaintContext;
import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.color.ColorSpace;
import java.awt.geom.AffineTransform;
import java.awt.geom.Rectangle2D;
import java.awt.image.ColorModel;

public class DoubleColor extends Color
{
	private static final long serialVersionUID = 6258488195375821278L;

	static volatile boolean DARK = UITools.isNotLight();

	private final Color darkColor;

	public DoubleColor(int rgb, int darkRGB)
	{
		this(new Color(rgb), new Color(darkRGB));
	}

	public DoubleColor(Color regular, Color dark)
	{
		super(regular.getRGB(), regular.getAlpha() != 255);
		darkColor = dark;
		//		DARK = UITools.isNotLight();
	}

	public static void setDark(boolean dark)
	{
		DARK = dark;
	}

	Color getDarkVariant()
	{
		return darkColor;
	}

	@Override
	public int getRed()
	{
		return DARK ? getDarkVariant().getRed() : super.getRed();
	}

	@Override
	public int getGreen()
	{
		return DARK ? getDarkVariant().getGreen() : super.getGreen();
	}

	@Override
	public int getBlue()
	{
		return DARK ? getDarkVariant().getBlue() : super.getBlue();
	}

	@Override
	public int getAlpha()
	{
		return DARK ? getDarkVariant().getAlpha() : super.getAlpha();
	}

	@Override
	public int getRGB()
	{
		return DARK ? getDarkVariant().getRGB() : super.getRGB();
	}

	@Override
	public Color brighter()
	{
		return new DoubleColor(super.brighter(), getDarkVariant().brighter());
	}

	@Override
	public Color darker()
	{
		return new DoubleColor(super.darker(), getDarkVariant().darker());
	}

	@Override
	public int hashCode()
	{
		return DARK ? getDarkVariant().hashCode() : super.hashCode();
	}

	@Override
	public boolean equals(Object obj)
	{
		return DARK ? getDarkVariant().equals(obj) : super.equals(obj);
	}

	@Override
	public String toString()
	{
		return DARK ? getDarkVariant().toString() : super.toString();
	}

	@Override
	public float[] getRGBComponents(float[] compArray)
	{
		return DARK
				? getDarkVariant().getRGBComponents(compArray)
				: super.getRGBComponents(compArray);
	}

	@Override
	public float[] getRGBColorComponents(float[] compArray)
	{
		return DARK
				? getDarkVariant().getRGBColorComponents(compArray)
				: super.getRGBComponents(compArray);
	}

	@Override
	public float[] getComponents(float[] compArray)
	{
		return DARK
				? getDarkVariant().getComponents(compArray)
				: super.getComponents(compArray);
	}

	@Override
	public float[] getColorComponents(float[] compArray)
	{
		return DARK
				? getDarkVariant().getColorComponents(compArray)
				: super.getColorComponents(compArray);
	}

	@Override
	public float[] getComponents(ColorSpace cspace, float[] compArray)
	{
		return DARK
				? getDarkVariant().getComponents(cspace, compArray)
				: super.getComponents(cspace, compArray);
	}

	@Override
	public float[] getColorComponents(ColorSpace cspace, float[] compArray)
	{
		return DARK
				? getDarkVariant().getColorComponents(cspace, compArray)
				: super.getColorComponents(cspace, compArray);
	}

	@Override
	public ColorSpace getColorSpace()
	{
		return DARK ? getDarkVariant().getColorSpace() : super.getColorSpace();
	}

	@Override
	public synchronized PaintContext createContext(ColorModel cm, Rectangle r,
			Rectangle2D r2d, AffineTransform xform, RenderingHints hints)
	{
		return DARK
				? getDarkVariant().createContext(cm, r, r2d, xform, hints)
				: super.createContext(cm, r, r2d, xform, hints);
	}

	@Override
	public int getTransparency()
	{
		return DARK
				? getDarkVariant().getTransparency()
				: super.getTransparency();
	}
}
